#!/usr/bin/perl
use Getopt::Std;
getopt("m:i:o", \%args); 
my $marker = $args{m};
my $input  = $args{i};
my $output  = $args{o};
chomp $marker;
chomp $input;
chomp $output;
if($marker eq "")
{
        die "entered markerfile name  is empty\n";

}
if($input eq "")
{
        die "entered input file name  is empty\n";

}
if($output eq "")
{
        die "entered output filename  is empty\n";

}
print "Marker : $marker Inputfile : $input Output : $output \n";
open BUFF,"<$marker" or die "Can't open $marker : $!";
while($line = <BUFF>)
{
	chomp $line;
	$line =~ s/AFFX-SNP_\d+__//g;
	
	@array = split(" ",$line);
  	$mark{$array[1]} = $array[3];	
	$mark_chr{$array[1]} = $array[0];
}
$input1 = $input;
$input1 =~ s/phased//g;

open(WRBUFF,">$output");
open BUFF1,"<$input" or die "Can't open $input : $!";
$line = <BUFF1>;
#print WRBUFF $line;
$line = <BUFF1>;
#print WRBUFF $line;
while($line = <BUFF1>)
{
        chomp $line;
        @array = split(" ",$line);
	shift(@array);
	$snp =  shift(@array);	
	$line = join(" ",@array);
 	$line2 = $mark_chr{$snp}." ".$snp." "."0"." ".$mark{$snp}." ".$line."\n";
	#$line2 =~ s/\r//g;
	#$line2 =~ s/\t/\s/g;
	#$line2 =~ s/\s+/\s/g;
	if($mark_chr{$snp} ne "")
	{		
		print WRBUFF $mark_chr{$snp}." ".$snp." "."0"." ".$mark{$snp}." ".$line."\n";
	}
}

